/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.app.gui;
import Facebook.GraphPublisherExample;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.net.URL;
import java.util.HashMap;
import javax.swing.JOptionPane;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import wshop.mail.Mail2;
import wshop.mail.MailConstruction;

/**
 *
 * @author Administrateur
 */
public class share extends javax.swing.JFrame {
URL url;
    Mail2 mail = new Mail2();
    String ing;
    String titre;
     String cat;

    /**
     * Creates new form Menu
     */
    public share(String ingredient , String titre,String categ) {

        initComponents();
     this.setResizable(false);
    setBounds(50, 50, 500, 427);
        getContentPane().setLayout(null);
       Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension windowSize = this.getSize();
        int windowX = Math.max(0, (screenSize.width  - windowSize.width ) / 2);
        int windowY = Math.max(0, (screenSize.height - windowSize.height) / 2);
        this.setLocation(windowX, windowY);
        ing=ingredient;
        this.titre= titre;
        cat=categ;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        mailsend = new javax.swing.JCheckBox();
        facebook = new javax.swing.JCheckBox();
        happy = new javax.swing.JCheckBox();
        pass = new javax.swing.JPasswordField();
        adress = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setTitle("Partage");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        getContentPane().setLayout(null);

        jLabel1.setFont(new java.awt.Font("Gabriola", 0, 18));
        jLabel1.setText("Publier sur Facebook");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(230, 40, 130, 31);

        jLabel3.setFont(new java.awt.Font("Gabriola", 0, 18));
        jLabel3.setText("Partager avec d'autres utilisateurs de l'application");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(150, 150, 270, 31);

        jLabel4.setFont(new java.awt.Font("Gabriola", 0, 18));
        jLabel4.setText("Envoyer a un ami");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(190, 220, 130, 31);

        jLabel5.setFont(new java.awt.Font("Gabriola", 0, 18));
        jLabel5.setText("Adresse");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(190, 250, 70, 31);

        jLabel6.setText("Mot de passe");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(190, 290, 100, 20);

        jLabel8.setText("Adresse reception");
        getContentPane().add(jLabel8);
        jLabel8.setBounds(180, 320, 110, 20);
        getContentPane().add(jTextField1);
        jTextField1.setBounds(300, 320, 180, 30);

        mailsend.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mailsendActionPerformed(evt);
            }
        });
        getContentPane().add(mailsend);
        mailsend.setBounds(430, 220, 20, 30);

        facebook.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                facebookActionPerformed(evt);
            }
        });
        getContentPane().add(facebook);
        facebook.setBounds(430, 40, 20, 30);
        getContentPane().add(happy);
        happy.setBounds(430, 151, 20, 30);
        getContentPane().add(pass);
        pass.setBounds(300, 290, 180, 20);
        getContentPane().add(adress);
        adress.setBounds(300, 250, 180, 30);

        jLabel7.setFont(new java.awt.Font("Gabriola", 3, 24));
        jLabel7.setText("Partager");
        jLabel7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel7MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel7MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabel7MouseExited(evt);
            }
        });
        getContentPane().add(jLabel7);
        jLabel7.setBounds(210, 360, 80, 40);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/app/gui/images/shareinter.jpg"))); // NOI18N
        jLabel2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        getContentPane().add(jLabel2);
        jLabel2.setBounds(0, -10, 510, 420);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void facebookActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_facebookActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_facebookActionPerformed

    private void mailsendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mailsendActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_mailsendActionPerformed

    private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseClicked
    if (facebook.isSelected()){
        //String ch= plat_list.getSelectedItem().toString();
        GraphPublisherExample gr = new GraphPublisherExample("AAAIO62GqZA2ABAIbffeoyQ5mVXHZCHPiE4llcBUAXlrFZBVBlgZBhigDh924tZAWvTBFNZCMuOByZCZBHeDMZBoatCkZBynuLJKcxxvPCH4o8xywZDZD");

//GraphPublisherExample g = new GraphPublisherExample("AAAIO62GqZA2ABAIbffeoyQ5mVXHZCHPiE4llcBUAXlrFZBVBlgZBhigDh924tZAWvTBFNZCMuOByZCZBHeDMZBoatCkZBynuLJKcxxvPCH4o8xywZDZD");
        gr.publishMessage(titre+"\n"+ing);
JOptionPane.showMessageDialog(this, "Recette partagée  !", "Share", JOptionPane.INFORMATION_MESSAGE);}
    
    if(happy.isSelected()){
            try {


     XmlRpcClient server = new XmlRpcClient();
     XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    config.setServerURL(new URL("http://happyfood.net84.net/xmlrpc.php"));
    XmlRpcClient client = new XmlRpcClient();
    client.setConfig(config);
  String[] categorie = new String[]{cat};
    HashMap<String,Object> params = new HashMap<String,Object>();
    params.put("wp_page_parent_id","0");
			 params.put("title",titre);
			 params.put("description",ing);
			 params.put(" mt_allow_comments","1");
			 params.put("publish","publish");
                         params.put("author","fares_benammar@hotmail.com");
                         params.put("categories",categorie);
     Object[] params2 = new Object[]{0,"admin","admin",params};
     String result =(String) client.execute("metaWeblog.newPost", params2);

   } catch (Exception exception) {
     System.err.println("JavaClient: " + exception);
   }
    }
    
    
    if (mailsend.isSelected()){
             mail.setMailAddressRecipient(jTextField1.getText());
        mail.setPwd(pass.getText());
        mail.setMailAddressSender(adress.getText());
        mail.setMailSubject("nouvelle recette");
        String[] lines = "recctte".split("\\n");
        String msg="";
        for(String s:lines){
            msg = msg+s;
        }
        mail.setMailObject(titre+"\n"+ing);
        //System.out.println(jTextArearObject.getToolTipText());

        MailConstruction mc = new MailConstruction();
        mc.getMailProperties();

        String s ="";//= this.cleanUrl(url);
        mc.getMailMessage(mail);
        
        mc.SendMessage();
        JOptionPane.showMessageDialog(this,"succes d'envoie", "Message envoyé", JOptionPane.INFORMATION_MESSAGE);
    }
    else{
        JOptionPane.showMessageDialog(this,"Veuillez selection une option", "Aucun Choix ", JOptionPane.ERROR_MESSAGE);
    }
    }//GEN-LAST:event_jLabel7MouseClicked

    private void jLabel7MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseEntered
       jLabel7.setForeground(Color.blue);
    }//GEN-LAST:event_jLabel7MouseEntered

    private void jLabel7MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseExited
       jLabel7.setForeground(Color.BLACK);
    }//GEN-LAST:event_jLabel7MouseExited

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(share.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(share.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(share.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(share.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                //new share().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField adress;
    private javax.swing.JCheckBox facebook;
    private javax.swing.JCheckBox happy;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JCheckBox mailsend;
    private javax.swing.JPasswordField pass;
    // End of variables declaration//GEN-END:variables

   
}
